<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Expenditure;
use App\Models\OrderManagement;
use App\Models\User;
use App\Models\WebUser;
use App\Services\RedisFun;
use Illuminate\Http\Request;


class MyOrderController extends Controller
{
    /**
     * Notes:我的订单接口
     * User: 沐辞
     * Date: 2021/11/15
     * Time: 10:45
     */
    public function orderSel(Request $request)
    {


        $uid =$request->get('uid');

        if (empty($uid)){
            return json_encode(['code'=>999,'msg'=>'请先登录','data'=>'']);
        }



       $data =  OrderManagement::where('uid',$uid)->paginate(5);

       return json_encode(['code'=>200,'msg'=>'请求成功','data'=>$data]);
    }


    /**
     * Notes:余额收入查询
     * User: 沐辞
     * Date: 2021/11/16
     * Time: 20:24
     */
    public function balanceSel(Request $request)
    {

        $uid =$request->get('uid');

        if (empty($uid)){
            return json_encode(['code'=>999,'msg'=>'请先登录','data'=>'']);
        }
        //根据用户id查询余额
       $money = WebUser::where('id',$uid)->first('money');
        return json_encode(['code'=>200,'msg'=>'查询成功','data'=>$money]);
    }


    /**
     * Notes:消费记录查询
     * User: 沐辞
     * Date: 2021/11/17
     * Time: 9:23
     */
    public function recordsSel(Request $request)
    {
        $uid =$request->get('uid');

        if (empty($uid)){
            return json_encode(['code'=>999,'msg'=>'请先登录','data'=>'']);
        }


        //查询当前跟用户相关的消费记录表
       $expenditure = Expenditure::where('uid',$uid)->paginate(15);

        return json_encode(['code'=>200,'msg'=>'查询成功','data'=>$expenditure]);

    }
}
